<?php
namespace app\index\controller;

use think\Session;
use think\Db;

class Earning extends Ubase
{
	public function __construct()
	{
		parent::__construct();
		if (!Session::has('aid')) {
			echo'<script>alert("请登录");window.location.href="/"</script>';
		}
	}

	public function index ()
	{
		$user = [];
        $no_title = db('notice')->order('create_time desc')->where('n_keywords',0)->field('n_title')->limit(3)->select();
        $this->assign('notice',$no_title);
        if (Session::has('aid')) {
            $user = db('ns_user')->where('id',Session::get('aid'))->find();
	        $this->assign('user',$user);
        // 用户矿机展示
        $machine = db('candy_machine')
        	-> where('uid',Session::get('aid'))
        	-> paginate()
        	-> each(function($items,$key){
        		$can= db('candym_type')->where('type_id',$items['type'])->find();
        		$items['typename'] = $can['type_name'];
        		return $items;
        	});
	        $this->assign('machine',$machine);
	        // 佣金记录
	        $charge = db('charge_log')->where('uid',Session::get('aid'))->select();
	        $this->assign('charge',$charge);
	        // 充值记录
	        $recharge = db('recharge')
	        	->where('uid',Session::get('aid'))
	        	->select();
	        $this->assign('recharge',$recharge);
	        // 提现记录
	        $draw = db('draw')->where('uid',Session::get('aid'))->select();
	        $this->assign('draw',$draw);
	        return $this->fetch();
        }
	}
}